<template>
	<view @touchmove.stop.prevent="() => {}">
		<myHead></myHead>
		<view class="box">
			<view class="boxCla">
				<view class="titleCla">
					添加地址
				</view>
				<view class="gongzuodidianCla">
					工作地点
				</view>
				<view class="addressCla" @click="addressClick">
					<view class="textCla">
						<view class="topCla">
							{{obj.NameAddress}}
						</view>
						<view class="BottomCla">
							{{obj.Address?obj.Address:'请选择地址'}}
						</view>
					</view>
					<view class="iconCla">
						<u-icon name="arrow-right" color="#C1C1C1" size="15"></u-icon>
					</view>
				</view>
				<view class="loucengCla">
					<view class="loutopCla">
						楼层/单元室/门牌号
					</view>
					<view class="inputCla">
						<u--input placeholder="请输入" v-model="obj.value"></u--input>
					</view>
				</view>

			</view>

		</view>
		<view class="baocunCla">
			<u-button type="primary" text="保存" color="#3476FE" @click="saveClick"></u-button>
		</view>
	</view>
</template>

<script>
	import myHead from "@/pages/component/baseHead.vue";
	import area from '@/pages/component/area.js';
	export default {
		data() {
			return {
				obj: {
					value: '', //楼层/单元室/门牌号
					NameAddress: '', //简短地址
					Address: "", //详细地址
					PcaAddress: '', //区 街道 地址
					AreaCode: null,
					CityCode: null,
					Latitude: 0,
					Longitude: 0,
					ProvinceCode: null,
				},
			}
		},
		components: {
			myHead,
		},
		onLoad(e) {
			this.obj = JSON.parse(e.data);
			console.log(this.obj, '99999999999999999')
		},
		methods: {
			//点击到地图
			addressClick() {
				let that = this;
				uni.chooseLocation({
					latitude: Number(that.obj.Latitude),
					longitude: Number(that.obj.longitude),
					success: function(res) {
						that.obj.Address = res.address;
						that.obj.NameAddress = res.name;
						that.obj.Latitude = res.latitude;
						that.obj.Longitude = res.longitude;
						that.geocoddata(res, that.obj);
						//逆地理编码  获取区和街道
						let objcked = {}
						objcked.Location = that.obj.Longitude + ',' + that.obj.Latitude;
						objcked.Key = that.$config.domain.aMapWebServerKey;
						that.$http.core.aMapRegeo(objcked).then((res1) => {
							if (res1.Success) {
								let district = res1.Result.addressComponent.district //区
								let businessAreas = res1.Result.addressComponent.businessAreas[0]
									.name //地名
								that.obj.PcaAddress = district + ' ' + businessAreas
							}
						})
					},
					fail: function(e) {}
				})
			},

			//根据经纬度 获取信息
			geocoddata(e, dataitem) {
				let that = this;
				let location = e.longitude + ',' + e.latitude;
				that.$util.geocoderegeo(location).then(res => {
					//详细地址信息
					//定位地址
					let adcode = res.data.regeocode.addressComponent.adcode
					area.forEach((item, index) => {
						item.children?.forEach((item1, index) => {
							item1.children?.forEach((item2, index) => {
								if (adcode == item2.value) {
									this.obj.ProvinceCode = item.value;
									this.obj.CityCode = item1.value;
									this.obj.AreaCode = item2.value;
								}
							})
						})
					})
				})
			},


			// 保存点击事件
			saveClick() {
				let CorpFullName = uni.getStorageSync("dianjiqiye").FullName;
				let obj = {
					FullName:CorpFullName,
					ProvinceCode: this.obj.ProvinceCode,
					CityCode: this.obj.CityCode,
					AreaCode: this.obj.AreaCode,
					PcaAddress: this.obj.PcaAddress,
					Address: this.obj.Address,
					ShortAddress: this.obj.NameAddress + this.obj.value,
					Longitude: this.obj.Longitude,
					Latitude: this.obj.Latitude,
					IsDefault: false,
					Type: 1
				}
				this.$http.core.tenantCr_address(obj).then((res) => {
					if(res.Success){
						uni.redirectTo({
							url: '/pages/views/packageC/type-recruit/zhiwei/zhiwei-page?data=' + JSON.stringify(this.obj)
						});
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100%;
		min-height: 100vh;
		background-color: #fff;

		.boxCla {
			padding: 0 40rpx;

			.titleCla {
				font-size: 48rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #000000;
				padding-top: 60rpx;
			}

			.gongzuodidianCla {
				font-size: 26rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #333333;
				margin-top: 60rpx;
			}

			.addressCla {
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1rpx solid #E7E7E8;
				margin-top: 16rpx;
				padding-bottom: 30rpx;

				.textCla {
					width: 95%;

					.topCla {
						font-size: 30rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #000000;
						margin-bottom: 10rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}

					.BottomCla {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #949494;
						//超出一行省略号
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}

				.iconCla {
					width: 5%;
				}
			}

			.loucengCla {
				margin-top: 30rpx;
				border-bottom: 1rpx solid #E7E7E8;

				.loutopCla {
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #333333;
				}

				.inputCla {
					/deep/.u-input--radius {
						border: none;
					}

					/deep/.u-input {
						padding: 21rpx 0;
					}
				}
			}

		}
	}

	.baocunCla {
		width: 100%;
		height: 198rpx;
		border-top: 1rpx solid #EBEFF4;
		position: fixed;
		bottom: 1rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		/deep/.u-button--square {
			width: 90%;
			height: 90rpx;
		}
	}
</style>